<extend name="Base/common" />

<block name="style">
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/Api/css/main.css">
</block>

<block name="Content">

<div class="page-group">
    <div class="page page-current">
    		<form action="#" method="post" id="wordCount">
        <div class="bar bar-standard bar-footer choose-people-footer">
            <p><button type="button" onclick="save()" class="button button-fill button-success">提交</button></p>
        </div>
        <div class="content native-scroll">
            <div class="advice-form">
                <textarea name="advice-form" id="content" name="content" cols="30" rows="10" placeholder="帮工小哥致力于给您提供优质的上门服务，欢迎提出宝贵意见或建议~"></textarea>
                <p><span id="text-num">200</span>/<span>200</span></p>
            </div>
        </div>
        </form>
    </div>
</div>

</block>

<block name="script">
<script type="text/javascript">

$(function(){
    var wordCount = $("#wordCount"), textArea = wordCount.find("textarea"), word = $("#text-num");
    statInputNum(textArea,word);
});

function statInputNum(textArea,numItem) {
    var max = numItem.text(), curLength;
    textArea.attr("maxlength", max);
    curLength = textArea.val().length;
    numItem.text(max - curLength);
    textArea.on('input propertychange', function () {
        numItem.text(max - $(this).val().length);
    });
}

function save(){
	
	var target = Think.U('Feedback/ajax_save');
	var content = $("#content").val();
	
	if(!content){
		$.alert('请填写意见或建议');
		return false;
	}
	
	$.confirm('确认提交？', function () {
		$.post(target, {'content':content}, function(data){
			
			if(data.status == 1){
				
				$.alert('提交成功', function () {
					var loginURL = Think.U('Index/index');
			        window.location.href = loginURL;
			        return false;
				});
			}else if(data.status == -201){
				
				$.confirm('身份认证已失效，请重新登录', function () {
			        var loginURL = Think.U('Public/login');
			        window.location.href = loginURL;
			        return false;
			    });
			}
		});
	});
}

</script>
</block>

